<?php

namespace app\admin\controller;

use app\common\controller\Article;
use app\common\controller\Classes;
use app\common\controller\Message;
use think\facade\Session;

/* 进入管理员界面以及数据绑定 继承自登录检测类~~ */

class Index extends CheckLoginBase
{

//   显示 管理员首页
    public function index(){
        $article = new Article();
        $classes = new Classes();
        $this->assign("title", "护蕾行动 | 管理员首页")
            ->assign("articles", $article->selectArticleAndClassPage(6))
            ->assign("total", $article->selectArticleAndClassPage(6)->total())
            ->assign("classes", $classes->selectAllClasses());
        return $this->fetch("index");
    }

//   显示 新增文章
    public function showAddAdmin(){
        $classes = new Classes();
        $this->assign("title", "护蕾行动 | 新增文章")
            ->assign("classes", $classes->selectAllClasses());
        return $this->fetch("index/add");
    }

    //显示 管理分类
    public function showListAdmin(){
        $classes = new Classes();
        $this->assign("title", "护蕾行动 | 管理分类")
            ->assign("classes", $classes->selectAllClasses());
        return $this->fetch("index/list");
    }

//   显示 管理留言板
    public function showMsgAdmin(){
        $msg = new Message();
        $this->assign("title", "护蕾行动 | 留言板管理")
            ->assign("messages0", $msg->selectAllMessage(0))
            ->assign("messages1", $msg->selectAllMessage(1));
        return $this->fetch("index/msg");
    }

    //   显示 访客记录
    public function showVisitor(){
        $visitor = new Visitor();
        $this->assign("title", "护蕾行动 | 访客记录")
            ->assign('visitors', $visitor->selectAll())
            ->assign('v_data', $visitor->selectData());
        return $this->fetch("index/visitor");
    }

//  显示  更改密码
    public function showChangePass(){
        $this->assign("title", "护蕾行动 | 修改密码");
        return $this->fetch("index/chagePass");
    }

   public function changeArticle($articleId){
        $article = new Article();
        $classes = new Classes();
       $this->assign("title", "护蕾行动 | 修改文章")
            ->assign("article", $article->selectArtAndClaFromClaId($articleId))
            ->assign("classes", $classes->selectAllClasses());
       return $this->fetch("index/changeArticle");
   }


//    退出登录
    public function exitLogin(){
        Session::delete("admin");
        $this->redirect("/admin/login");
    }
}